#ifndef __GLF_REMOTE_CANVAS_H_INCLUDED__
#define __GLF_REMOTE_CANVAS_H_INCLUDED__

#include <glf/config.h>

#include <glf/core/types.h>
#include <glf/math/vec3.h>
#include <glf/remote/renderer.h>

#include <list>
#include <vector>

namespace glf
{
	namespace remote
	{

		class Renderer;

		//Canvas
		class Canvas
		{
		public:

			//Color
			enum Color
			{
				COLOR_WHITE,
				COLOR_GRAY,
				COLOR_RED,
				COLOR_GREEN,
				COLOR_BLUE,
				COLOR_COUNT
			};

			//ShapeType
			enum ShapeType
			{
				ST_CIRCLE,
				ST_CROSS,
				ST_POINT,
				ST_RECT,
				ST_TRIANGLE
			};		

			//OrientationType
			enum OrientationType
			{
				OT_TOP,
				OT_LEFT,
				OT_BOTTOM,
				OT_RIGHT
			};		

		public:
			//Shape
			struct Shape
			{
				Shape() :  
				mType(ST_CIRCLE), 
				mFill(true),
				mPos(0.0f, 0.0f), 
				mSize(0.0f, 0.0f),
				mOrientation(OT_TOP),
				mColor(COLOR_GRAY),
				mDurationMS(1000.0f),
				mAlpha(1.0f)
			{
			}
			ShapeType mType;
			bool mFill;
			Point<float> mPos;
			Point<float> mSize;
			OrientationType mOrientation;
			Color mColor;
			float mDurationMS;
			float mAlpha;
			};

		public:
			Canvas();

		public:		
			Point<float> ConvertPosScreen2Canvas(Point<short> pos);
			Point<float> ConvertLength2Size(float length);
			void PostDrawShape(const Shape &shape);
			void PostSignal(Color color, bool micro = false);
			void Update(Renderer *renderer);

		private:		
			void cvBegin(Renderer::PrimitiveType type);
			void cvColor(Canvas::Color color, float alpha = 1.0f);		
			void cvOrientation(OrientationType orientation);
			void cvCircle2fv(const float *p, const float *r, bool fill);		
			void cvCross2fv(const float *p, const float *r, bool fill);		
			void cvDrawShape(const Shape &shape, float alpha = 1.0f);
			void cvEnd();		
			void cvPoint2fv(const float *p, bool fill);
			void cvRect2fv(const float *p1, const float *p2, bool fill);
			void cvTriangle2fv(const float *p, const float *r, bool fill);
			void cvVertex2f(float x, float y, float u = 0.0f, float v = 0.0f);

		private:		
			std::list<Shape> mShapes;
			float mLastUpdateTimeMS;
			Renderer *mCurrentRenderer;
			Vec4f mCurrentColor;
			float mCurrentOrientation;
			Renderer::PrimitiveType mCurrentType;
			size_t mCurrentVertexCount;
			std::vector<Vec4f> mCurrentVertices;
		};

	} //eon remote
} //eon glf


#endif //__GLF_REMOTE_CANVAS_H_INCLUDED__